<?php
if(!preg_match("/^\d{10}$/", $_POST['studentId'])){
	$result = array(
		"error" => urlencode("信息不全")
	);
	echo urldecode(json_encode($result));
	exit;
}

include_once($_SERVER['DOCUMENT_ROOT']."/common/config.php");
$_conn = connect_mysql('wit_grade');

$studentId = $_POST['studentId'];
$sql = "SELECT * FROM wit_gpa_tmp WHERE studentId = '{$studentId}'";
$result = mysqli_query($_conn, $sql) or die(mysqli_error($_conn));
if(!mysqli_num_rows($result)){
	$result = array(
		"error" => urlencode("暂无数据，请检查学号是否打错，有疑问请联系助手君哦（不过助手君是绝对不会承认把你的成绩漏掉了的事")
	);
	echo urldecode(json_encode($result));
	exit;
}

$row = mysqli_fetch_array($result);
$percent = round($row['num'] / 24765 * 100);
$total = round($row['total']);
$gpa = round($row['gpa']);
$name = $row['studentName'];
if($percent < 10){
	$title = '已放弃治疗';
	$img = '罢学.png';
}
else if($percent < 20){
	$title = '寝室万年撸';
	$img = '罢学.png';
}
else if($percent < 30){
	$title = '霸占后三排';
	$img = '学酥.png';
}
else if($percent < 40){
	$title = '来年当学霸';
	$img = '学酥.png';
}
else if($percent < 50){
	$title = '百度小王子';
	$img = '学渣.png';
}
else if($percent < 60){
	$title = '考前突击队';
	$img = '学渣.png';
}
else if($percent < 70){
	$title = '四教占座狂';
	$img = '学霸.png';
}
else if($percent < 80){
	$title = '图书馆霸主';
	$img = '学霸.png';
}
else if($percent < 90){
	$title = '奖学金狂魔';
	$img = '学神.png';
}
else if($percent <= 100){
	$title = '小宇宙爆发';
	$img = '学神.png';
}
$base = round($row['base']);
$bonus = round($row['bonus']);

$result = array(
	"error" => null,
	"name" => $name,
	"total" => $total,
	"score" => $gpa,
	"base" => $base,
	"percent" => $percent,
	"bonus" => $bonus,
	"title" => urlencode($title),
	"img" => urlencode($img)
);

echo urldecode(json_encode($result));